import request from '@/utils/request';
import URLS from './APIUrlDefine';
import {CURRENT_TOKEN} from '@/components/Authorized/renderAuthorize';

/**
 * 创建新学校
 * @param data
 */
export async function CreateNewSchool(data: any) {
  return request(`${URLS.CREAT_NEW_SCHOOL}`, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    data: JSON.stringify(data),
  });
}

/**
 * 删除学校
 * @param data
 */
export async function DeleteSchool(data: any) {
  return request(`${URLS.CREAT_NEW_SCHOOL}/${data}`, {
    method: 'DELETE',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
    },
    params: data,
  });
}

/**
 * 更新新学校
 * @param data
 */
export async function UpdateSchool(data: any) {
  return request(`${URLS.CREAT_NEW_SCHOOL}`, {
    method: 'PUT',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    data: JSON.stringify(data),
  });
}

/**
 * 获取学校列表
 * @param data
 */
export async function GetSchoolList(data: any) {
  return request(`${URLS.GET_SCHOOL_LIST}/${data.current}/${data.pageSize}`, {
    method: 'GET',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
    },
    params: data,
  }).then((response) => {
    const data = response.data;
    //console.log(data);
    const result = {
      data: data.records,
      total: data.total,
      success: true,
      pageSize: data.size,
      current: parseInt(`${data.current}`, 10) || 1,
    };
    return Promise.resolve(result);
  });
}

/**
 * 获取学校列表  下拉菜单用
 * @param data
 */
export async function SearchGetSchoolList(data: any) {
  return request(`${URLS.GET_SCHOOL_LIST}/${data.current}/${data.pageSize}`, {
    method: 'GET',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
    },
    //params: data,
  }).then((response) => {
    const data = response.data.records;
    return Promise.resolve(data);
  }).catch(e => {
    console.error(e)
  });
}

/**
 * 获取学院列表   下拉菜单用
 * @param data
 */
export async function SearchGetCollegeList(data: any) {
  if (data.id === undefined)
    data.id = -1;
  return request(`${URLS.GET_COLLEGE_LIST_BY_SCHOOL}/${data.id}`, {
    method: 'GET',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
    },
    params: data,
  }).then((response) => {
    const data = response.data;
    return Promise.resolve(data);
  }).catch(e => {
    console.error(e)
  });
}

/**
 * 获取学校下的所有院系
 * @param data
 */
export async function GetCollegeListBySchool(data: any) {
  return request(`${URLS.GET_COLLEGE_LIST_BY_SCHOOL}/${data.id}`, {
    method: 'GET',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
    },
    params: data,
  }).then((response) => {
    const data = response.data;
    //console.log(data);
    const result = {
      data: data,
      total: data?.length,
      success: true,
      //pageSize: data.size,
      current: 1
    };
    //console.log(result)
    return Promise.resolve(result);
  });
}

/**
 * 获取学院列表
 * @param data
 */
export async function GetCollgeList(data: any) {
  return request(`${URLS.GET_COLLEGE_LIST}/${data.current}/${data.pageSize}?tag=${data.tag}`, {
    method: 'GET',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
    },
    params: data,
  }).then((response) => {
    const data = response.data;
    const result = {
      data: data.records,
      total: data.total,
      success: true,
      pageSize: data.size,
      current: parseInt(`${data.current}`, 10) || 1,
    };
    return Promise.resolve(result);
  });
}

/**
 * 搜索学院
 * @param data
 */
export async function SearchGetCollgeList(keyword: string) {
  return request(`${URLS.SEARCH_COLLEGE}?key=${keyword}`, {
    method: 'GET',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
    },
  }).then((response) => {
    const data = response.data;
    return Promise.resolve(data);
  });
}

/**
 * 修改学院状态
 * @param data
 */
export async function ChangeCollegeState(data: any) {
  console.log(data)
  return request(`${URLS.CHANGE_COLLEGE_STATE}?id=${data.id}&state=${data.state}`, {
    method: 'PUT',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    params: data,
  });
}

/**
 * 修改学校状态
 * @param data
 */
export async function ChangeSchoolState(data: any) {
  console.log(data)
  return request(`${URLS.UPDATE_SCHOOL_STATE}?id=${data.id}&state=${data.state}`, {
    method: 'PUT',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    params: data,
  });
}

/**
 * 更新学院信息
 * @param data
 */
export async function UpdateCollege(data: any) {
  return request(`${URLS.UPDATE_COLLEGE}`, {
    method: 'Put',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    data: JSON.stringify(data),
  });
}

/**
 * 创建新的学院信息
 * @param data
 */
export async function CreateNewCollge(data: any) {
  return request(`${URLS.CREATE_NEW_COLLEGE}`, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    data: JSON.stringify(data),
  });
}

/**
 * 删除指定的学院信息
 * @param data
 */
export async function DeleteNewCollge(data: any) {
  return request(`${URLS.DELETE_COLLEGE}/${data.id}`, {
    method: 'DELETE',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
    },
    params: data,
  });
}

/**
 * 获取专业列表
 * @param data
 */
export async function GetMajorList(data: any) {
  return request(`${URLS.GET_MAJOR_LIST}/${data.current}/${data.pageSize}`, {
    method: 'GET',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
    },
    params: data,
  }).then((response) => {
    const data = response.data;
    const result = {
      data: data.records,
      total: data.total,
      success: true,
      pageSize: data.size,
      current: parseInt(`${data.current}`, 10) || 1,
    };
    return Promise.resolve(result);
  });
}

/**
 * 获取专业列表
 * @param data
 */
export async function GetCollegeMajorList(data: any) {
  return request(`${URLS.GET_COLLEGE_MAJOR_LIST}/${data.id}`, {
    method: 'GET',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
    },
    params: data,
  }).then((response) => {
    const data = response.data;

    return Promise.resolve(data);
  });
}

/**
 * 搜索专业
 * @param data
 */
export async function SearchGetMajor(keyword: string) {
  return request(`${URLS.SEARCH_MAJOR}?key=${keyword}`, {
    method: 'GET',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
    },
  }).then((response) => {
    const data = response.data;
    return Promise.resolve(data);
  });
}

/**
 * 修改专业状态
 * @param data
 */
export async function ChangeMajorState(data: any) {
  return request(`${URLS.CHANGE_MAJOR_STATE}`, {
    method: 'PUT',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    params: data,
  });
}

/**
 * 创建新的专业信息
 * @param data
 */
export async function CreateNewMajor(data: any) {
  return request(`${URLS.CREATE_NEW_MAJOR}`, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    data: JSON.stringify(data),
  });
}

/*
* 修改专业信息
* */
export async function UpdateMajor(data: any) {
  return request(`${URLS.UPDATE_MAJOR}`, {
    method: 'PUT',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    data: JSON.stringify(data),
  });
}

/**
 * 删除指定的专业信息
 * @param data
 */
export async function DeleteMajor(data: any) {
  return request(`${URLS.DELETE_MAJOR}/${data}`, {
    method: 'DELETE',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
    },
    params: data,
  });
}


/**
 * 获取班级列表
 * @param data
 */
export async function GetClassList(data: any) {
  return request(`${URLS.GET_CLASS_LIST}/${data.current}/${data.pageSize}`, {
    method: 'GET',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
    },
    params: data,
  }).then((response) => {
    const data = response.data;
    const result = {
      data: data.records,
      total: data.total,
      success: true,
      pageSize: data.size,
      current: parseInt(`${data.current}`, 20) || 1,
    };
    return Promise.resolve(result);
  });
}

// /**
//  * 获取班级列表
//  * @param data
//  */
// export async function GetMajorClassList(data: any) {
//   return request(`${URLS.GET_CLASS_LIST}/${data.current}/${data.pageSize}`, {
//     method: 'GET',
//     headers: {
//       Authorization: `Bearer ${CURRENT_TOKEN}`,
//     },
//     params: data,
//   }).then((response) => {
//     const data = response.data;
//     const result = {
//       data: data.records,
//       total: data.total,
//       success: true,
//       pageSize: data.size,
//       current: parseInt(`${data.current}`, 20) || 1,
//     };
//     return Promise.resolve(result);
//   });
// }

/**
 * 获取班级列表
 * @param data
 */
export async function GetMajorClassList(data: any) {
  return request(`${URLS.GET_MAJOR_CLASS_LIST}/${data.id}`, {
    method: 'GET',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
    },
    params: data,
  }).then((response) => {
    const data = response.data;

    return Promise.resolve(data);
  });
}

/**
 * 修改班级状态
 * @param data
 */
export async function ChangeClassState(data: any) {
  return request(`${URLS.CHANGE_CLASS_STATE}`, {
    method: 'PUT',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    params: data,
  });
}

/**
 * 创建新的班级信息
 * @param data
 */
export async function CreateNewClass(data: any) {
  return request(`${URLS.CREATE_NEW_CLASS}`, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    data: JSON.stringify(data),
  });
}

/**
 * 修改班级信息
 * @param data
 */
export async function UpdateClass(data: any) {
  return request(`${URLS.CREATE_NEW_CLASS}`, {
    method: 'PUT',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    data: JSON.stringify(data),
  });
}

/**
 * 删除指定的班级
 * @param data
 */
export async function DeleteClass(data: any) {
  return request(`${URLS.DELETE_CLASS}/${data}`, {
    method: 'DELETE',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
    },
    params: data,
  });
}

/**
 * 获取学生列表
 * @param data
 */
export async function GetStudentList(data: any) {
  return request(`${URLS.GET_STUDENT_LIST}/${data.current}/${data.pageSize}`, {
    method: 'GET',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
    },
    params: data,
  }).then((response) => {
    const data = response.data;
    const result = {
      data: data.records,
      total: data.total,
      success: true,
      pageSize: data.size,
      current: parseInt(`${data.current}`, 10) || 1,
    };
    return Promise.resolve(result);
  });
}

/**
 * 创建新的学生信息
 * @param data
 */
export async function CreateNewStudent(data: any) {
  return request(`${URLS.CREATE_NEW_STUDENT}`, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    timeout: 300000,
    data: JSON.stringify(data),
  });
}

/**
 * 创建新的学生信息
 * @param data
 */
export async function ImportStudents(data: any) {
  return request(`${URLS.IMPORT_STUDENTS}`, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    data: JSON.stringify(data),
  });
}

/**
 * 删除指定的学生信息
 * @param data
 */
export async function DeleteStudent(data: any) {
  return request(`${URLS.DELETE_STUDENT}/${data.id}`, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    params: data,
  });
}


/**
 * 搜索老师
 * @param data
 */
export async function SearchTeacher(keyword: string) {
  return request(`${URLS.SEARCH_TEACHER}?key=${keyword}`, {
    method: 'GET',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
    },
  }).then((response) => {
    const data = response.data;
    return Promise.resolve(data);
  });
}

export async function DeleteTeacher(data: any) {
  return request(`${URLS.DELETE_TEACHER_ROLE}/${data.id}`, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    // params: data,
  });
}


/**
 * 获取老师角色
 * @param data
 */
export async function GetTeacherRole(data: any) {
  return request(`${URLS.GET_TEACHER_ROLE}/${data.id}`, {
    method: 'GET',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
    },
  }).then((response) => {
    const data = [];
    response.data.map((item, index) => {
      if (item.roleId !== 10000) {
        data.push(item.roleId)
      }
    })
    return Promise.resolve(data);
  });
}

/**
 *
 * @param data
 */
export async function ChangeTeacherRole(data: any) {
  return request(`${URLS.CHANGE_TEACHER_ROLE}`, {
    method: 'PUT',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    params: data,
  })
}

/**
 * 修改老师状态
 * @param data
 */
export async function ChangeTeacherState(data: any) {
  return request(`${URLS.CHANGE_TEACHER_STATE}`, {
    method: 'PUT',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
      'content-type': 'application/json',
    },
    params: data,
  });
}

/**
 * 获取老师详细信息
 * @param data
 */
export async function GetTeacherDetail(data: any): Promise<any> {
  return request(`${URLS.GET_TEACHER_DETAIL}/${data.id}`, {
    method: 'GET',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
    },
  }).then((response) => {
    const data = response.data;
    return Promise.resolve(data);
  });
}


/**
 * 获取老师详细信息
 * @param data
 */
export async function GetTeacherList(data: any): Promise<any> {
  return request(`${URLS.GET_TEACHER_LIST}/${data.current}/${data.pageSize}`, {
    method: 'GET',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
    },
  }).then((response) => {
    const data = response.data;
    const result = {
      data: data.records,
      total: data.total,
      success: true,
      pageSize: data.size,
      current: parseInt(`${data.current}`, 10) || 1,
    };
    return Promise.resolve(result);
  });
}


/**
 * 审核同意老师认证信息
 * @param data
 */
export async function AcceptTeacherInfo(data: any): Promise<any> {
  return request(`${URLS.ACCEPT_TEACHER_INFO}/${data.id}`, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
    },
  });
}

/**
 * 审核拒绝老师认证信息
 * @param data
 */
export async function RefuseTeacherInfo(data: any): Promise<any> {
  return request(`${URLS.REFUSE_TEACHER_INFO}/${data.id}`, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
    },
  });
}

/**
 * 审核同意老师认证信息
 * @param data
 */
export async function AcceptStudentInfo(data: any): Promise<any> {
  return request(`${URLS.ACCEPT_STUDENT_INFO}/${data.id}`, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
    },
  });
}

/**
 * 审核拒绝老师认证信息
 * @param data
 */
export async function RefuseStudentInfo(data: any): Promise<any> {
  return request(`${URLS.REFUSE_STUDENT_INFO}/${data.id}`, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${CURRENT_TOKEN}`,
    },
  });
}
